<template>
  <div class="page-common-layout">
    <div class="page-common-content">
      <a-tabs default-active-key="1" @change="tabChange">
        <a-tab-pane key="1" tab="高德地图">
          <div id="amap-container"></div>
        </a-tab-pane>
        <a-tab-pane key="2" tab="百度地图" force-render>
          <baidu-map
            class="bm-view"
            :center="center"
            :zoom="zoom"
            @ready="bmHandler"
          >
            <bm-navigation anchor="BMAP_ANCHOR_TOP_LEFT"></bm-navigation>
            <bm-city-list anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-city-list>
            <!--<bm-map-type :map-types="['BMAP_NORMAL_MAP', 'BMAP_HYBRID_MAP']" anchor="BMAP_ANCHOR_TOP_RIGHT"></bm-map-type>-->
            <bm-marker
              :position="bmPosition"
              :dragging="false"
              animation="BMAP_ANIMATION_BOUNCE"
            >
              <bm-info-window
                :show="show"
                style="font-size:13px"
              ></bm-info-window>
            </bm-marker>
          </baidu-map>
        </a-tab-pane>
      </a-tabs>
    </div>
  </div>
</template>

<script>
import AMapLoader from "@amap/amap-jsapi-loader";
window._AMapSecurityConfig = {
  securityJsCode: "ecfcb87ee130b34b5f0d25862f5ef080",
};
var amap;
export default {
  name: "amap",
  data() {
    return {
      center: { lng: 0, lat: 0 },
      zoom: 3,
      aMap: null,
      mouseTool: null,
      overlays: [],
      auto: null,
      placeSearch: null,
      markerPoint: { lng: 108.951, lat: 34.3285 },
      show: false,
      isBig: false,
      values: [],
      bmPosition: { lng: 108.951, lat: 34.3285 },
    };
  },
  mounted() {
    this.initMap();
  },
  components: {},
  methods: {
    tabChange() {},
    initMap() {
      AMapLoader.load({
        key: "4a9b32384ac2ef8437f61e2357874137", // 申请好的Web端开发者Key，首次调用 load 时必填
        version: "2.0", // 指定要加载的 JSAPI 的版本，缺省时默认为 1.4.15
        plugins: [
          "AMap.Scale",
          "AMap.ToolBar",
          "AMap.ControlBar",
          "AMap.MouseTool",
          "AMap.MapType",
          "AMap.HawkEye",
          "AMap.Geolocation",
        ], // 需要使用的的插件列表，如比例尺'AMap.Scale'等
      })
        .then((AMap) => {
          this.amap = new AMap.Map("amap-container", {
            //设置地图容器id
            viewMode: "2D", //是否为3D地图模式
            zoom: 5, //初始化地图级别
            center: [105.602725, 37.076636], //初始化地图中心点位置
            resizeEnable: true,
          });
          this.amap.addControl(new AMap.Scale()); // 添加左下角的比例尺
          let toolBar = new AMap.ToolBar({
            position: {
              bottom: "210px",
              right: "35px",
            },
          });
          let controlBar = new AMap.ControlBar({
            position: {
              bottom: "280px",
              right: "10px",
            },
          });
          this.amap.addControl(toolBar); // 添加右下角的放大缩小
          this.amap.addControl(controlBar); // 方向盘
          this.amap.addControl(new AMap.MapType()); // 添加右上角的标准图和卫星图  和路况
        })
        .catch((e) => {
          // console.log(e);
        });
    },
    bmHandler({ BMap, map }) {
      this.center.lng = 116.404;
      this.center.lat = 39.915;
      this.zoom = 15;
    },
  },
};
</script>

<style scoped>
#amap-container {
  width: 100%;
  height: 100%;
}

.bm-view {
  width: 100%;
  height: 100%;
}

/deep/ .ant-tabs {
  height: 100%;
}

/deep/.ant-tabs-content {
  height: calc(100% - 56px);
}
</style>
